app.controller('csController', function ($scope, $controller, csService) {

    $controller('baseController', {$scope: $scope});//继承


    //获得登录用户的id并显示未选的课
    $scope.initNoData = function () {
        csService.initData().success(
            function (response) {
                $scope.uid = response.data;
                $scope.getNoCss(response.data);
            }
        );
    }

    //获得登录用户的id并显示已选的课
    $scope.initData = function () {
        csService.initData().success(
            function (response) {
                $scope.uid = response.data;
                $scope.getCSs(response.data);
            }
        );
    }

    //读取已选的课
    $scope.getCSs = function (uid) {
        csService.getCSs(uid).success(
            function (response) {
                $scope.csList = response;
            }
        );
    }

    //读取未选的课
    $scope.getNoCss = function (uid) {
        csService.getNoCss(uid).success(
            function (response) {
                $scope.noCsList = response;
            }
        );
    }

    //选课
    $scope.addCSs = function (cid, uid) {
        //判断是否选中选项
        if (confirm("确认选择该课程？")) {
            //获取选中的复选框
            csService.addCSs(cid, uid).success(
                function (response) {
                    alert(response.message);
                    if (response.success) {
                        window.location = "/student/goods.html";
                    }
                }
            );
        }

    }
    //退课
    $scope.quitCSs = function (cid, uid) {
        if (confirm("确认退出该课程？")) {
            csService.quitCSs(cid, uid).success(
                function (response) {
                    alert(response.message);
                    if (response.success) {
                        window.location = "/student/goods_edit.html";
                    }
                }
            );
        }

    }

});